﻿using System; using HISModels.ViewModel;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using SignalR.Hubs;
using SignalR.Hosting.AspNet;
using SignalR.Infrastructure;
using SignalR;

namespace HIS.Push {

    public class ChanelInstance {

        private readonly static Lazy<ChanelInstance> _instance = new Lazy<ChanelInstance>(() => new ChanelInstance());

        private ChanelInstance() {

        }

        public static ChanelInstance Instance {
            get {
                return _instance.Value;
            }
        }

        public void SendToSpesificDoctor(string mess, string ClientSessionId) {
            /// setWorklistODPDoctor is javascript client
            GetOPDClients()[ClientSessionId].setWorklistOPDDoctor(mess);
        }

        public void SendToAllOPD(string sDateTime)
        {
            GetOPDClients().setListPatient(sDateTime);
        }

        private static dynamic GetOPDClients() {
            return AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<HIS.Push.OpdHub>();
        }

        private static dynamic GetIPDClients() {
            return AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<HIS.Push.IpdHub>();
        }

        ~ChanelInstance() {
        }
    }
}